<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('view')) {
            Schema::create('view', function (Blueprint $table) {
                $table->increments('id')->comment('主键ID');
                $table->tinyInteger('type')->default(1)->comment('类型（1：首页，2：导航内容，3、广告、4、友情链接）');
                $table->date('date')->nullable()->comment('访问日期');
                $table->string('ip', 16)->default('')->comment('访问ip');
                $table->integer('data_id')->default(0)->comment('数据ID（首页数据默认为0）');
                $table->integer('pv')->default(0)->comment('访问数');
                $table->datetime('created_at')->nullable()->useCurrent()->comment('创建时间');
                $table->datetime('updated_at')->nullable()->useCurrent()->useCurrentOnUpdate()->comment('更新时间');
                $table->datetime('deleted_at')->nullable()->comment('删除时间');
            });
            DB::statement(sprintf("ALTER TABLE `%s%s` comment '%s'", config('database.connections.mysql.prefix'), 'view', '访问表'));
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('view');
    }
};
